Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

without short manes of instrument and platform//two new unittests are … #80

Merged
merged 6 commits into from
Mar 30, 2020

Conversation

opsdep
Copy link
Contributor

@opsdep opsdep commented Mar 24, 2020

…added

@opsdep opsdep requested a review from akorosov March 24, 2020 20:51
Copy link
Member

@akorosov akorosov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!
But we still have unique_together in the Source model. I guess that should stay like it is. But we have to test if it is working. That's why I suggested to add one more test.
Please add this test and fix small things here and there.

@@ -206,6 +206,37 @@ def test_source(self):
i = Instrument.objects.get(short_name='MODIS')
source = Source(platform=p, instrument=i)
source.save()

def test_source_without_short_names(self):
p = Platform.objects.get(pk=796)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better not to add new entries to vocabularies fixtures and rather to use existing entries with empty short_name, long_name, etc.

self.assertEqual(source.instrument.category, "category_without_short_name")

def test_source_empty_without_short_names(self):
Platform2=Platform(category = '',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use conventional for variable naming: variable names start from block letters. Class names from capital. Read more here:
http://www.python.org/dev/peps/pep-0008/
And here:
https://nansat.readthedocs.io/en/latest/source/conventions.html

self.assertEqual(source2.platform.long_name, "")
self.assertEqual(source2.platform.series_entity, "")
self.assertEqual(source2.instrument.long_name, "")
self.assertEqual(source2.instrument.category, "")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is important to have one more test :

Use get_or_create to add one Source pointing to one Instrument and one Latform with short names.
Use get_or_create to add exactly the same source. Test assert that create equals False in this case and source2 is equal to source 1.

Use get_or_create to add Source with the same Instrument but a different Platform (also with empty short name). Test assert that in that case create equals True and source 3 is not equal source 1.

@@ -17483,6 +17483,18 @@
"model": "vocabularies.instrument",
"pk": 1457
},
{
Copy link
Member

@akorosov akorosov Mar 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed. We have already enough instruments and platforms with empty fields in fixtures.

@@ -119,8 +119,8 @@ class PlatformManager(VocabularyManager):
short_name='Short_Name',
long_name='Long_Name')

def get_by_natural_key(self, short_name):
return self.get(short_name=short_name)
#def get_by_natural_key(self, short_name):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to remove completely rather than comment out. We wills still have it in git history. And the code remains cleaner without.

@akorosov
Copy link
Member

One minor comment. Please use conventions for branch naming as well next time. It could have been named e.g. issue1-natural-key, or something similar.

@opsdep
Copy link
Contributor Author

opsdep commented Mar 26, 2020

@akorosov
Dear Anton, please review the third test as well. I have modified the tests and return the fixture to their original state based on your comments.

@opsdep opsdep requested a review from akorosov March 26, 2020 13:55
@akorosov
Copy link
Member

Yeah, test is good. Please also change other things.

@opsdep
Copy link
Contributor Author

opsdep commented Mar 27, 2020

@akorosov
now it is ready to be merged! I have modified them based on your suggestions.

@akorosov
Copy link
Member

Not yet.
Look carefully at the pending comments. E.g. check lines:
source,_ = Source.objects.get_or_create(platform=p, instrument=i)
and
i2 = Instrument.objects.get(pk=136)# "short_name": "SCATTEROMETERS"

Next time it would be easier if you click on 'Commit suggestion' so that it disappears from the discussion above.

source2, created = Source.objects.get_or_create(platform=p, instrument=i)
self.assertEqual(created, 0)
self.assertEqual(source2, source)
i2 = Instrument.objects.get(pk=136)# "short_name": "SCATTEROMETERS"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here short_name should also be empty. But it should be instrument other than 139.

i = Instrument.objects.get(pk=139)# "short_name": ""
source,_ = Source.objects.get_or_create(platform=p, instrument=i)
source2, created = Source.objects.get_or_create(platform=p, instrument=i)
self.assertEqual(created, 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.assertEqual(created, 0)
self.assertFalse(created2)

p = Platform.objects.get(pk=661) # "short_name": ""
i = Instrument.objects.get(pk=139)# "short_name": ""
source,_ = Source.objects.get_or_create(platform=p, instrument=i)
source2, created = Source.objects.get_or_create(platform=p, instrument=i)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
source2, created = Source.objects.get_or_create(platform=p, instrument=i)
source2, created2 = Source.objects.get_or_create(platform=p, instrument=i)


p = Platform.objects.get(pk=661) # "short_name": ""
i = Instrument.objects.get(pk=139)# "short_name": ""
source,_ = Source.objects.get_or_create(platform=p, instrument=i)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
source,_ = Source.objects.get_or_create(platform=p, instrument=i)
source,create1 = Source.objects.get_or_create(platform=p, instrument=i)
self.assertTrue(create1)

def test_empty_short_names(self):
''' creating objects without short_name and creating source
based on them'''
Platform2=Platform(category = '',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Platform2=Platform(category = '',
platform2=Platform(category = '',

@opsdep
Copy link
Contributor Author

opsdep commented Mar 30, 2020

@akorosov
Dear anton, please check it once again! :) 77b7905

@akorosov
Copy link
Member

Great job, thank you @aanersc !

@akorosov akorosov merged commit d217002 into master Mar 30, 2020
akorosov pushed a commit that referenced this pull request Mar 30, 2020
akorosov pushed a commit that referenced this pull request Mar 30, 2020
@akorosov akorosov deleted the fix_issue_1 branch March 30, 2020 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants